/*=======================================初始化步骤导向=====================================*/
$(document).ready(function() {
    $('#demo-main-wz').bootstrapWizard({
        tabClass		: 'wz-steps',
        nextSelector	: '.next',
        previousSelector	: '.previous',
        onTabClick: function(tab, navigation, index) {
            return false;
        },
        onInit : function(){
            $('#demo-main-wz').find('.finish').hide().prop('disabled', true);
        },
        onPrevious: function(tab, navigation, index){

        	//是否切换到tap2
        	if(index == 1){
        		//若优先级和状态均未选中，则直接跳转至tap1
        		if(syncFlag == "jira_sync_cts"){
        			 if(!document.getElementById("jira-priority").checked && !document.getElementById("jira-state").checked){
            			 $('#demo-main-wz').bootstrapWizard('first');
                   	  	 return false;
            		 }
        		}else if(syncFlag == "cts_sync_jira"){
        			if(!document.getElementById("priority").checked){
           			 $('#demo-main-wz').bootstrapWizard('first');
                  	  	 return false;
        			}
        		}


        	}
        },
        onNext: function(tab, navigation, index){
        	console.log("index: "+index);
        	//是否切换到tap2
        	if(index == 1){

        		if(syncFlag == "jira_sync_cts"){
        			 if(document.getElementById("jira-priority").checked && document.getElementById("jira-state").checked){
            			 $("#jira_priority_mapping").show();
            			 $("#jira_state_mapping").show();
            			 var priorityCheck = true;
            			 var stateCheck = true;
            			 syncData.listPriorityOrState(priorityCheck,stateCheck,projectKey);
                      }else if(document.getElementById("jira-priority").checked){
                    	  $("#jira_priority_mapping").show();
                          $("#jira_state_mapping").hide();
                          var priorityCheck = true;
             			  var stateCheck = false;
             			  syncData.listPriorityOrState(priorityCheck,stateCheck,projectKey);
                      }else if(document.getElementById("jira-state").checked){
                    	  $("#jira_priority_mapping").hide();
                          $("#jira_state_mapping").show();
                          var priorityCheck = false;
         			 	  var stateCheck = true;
             			  syncData.listPriorityOrState(priorityCheck,stateCheck,projectKey);
                      }else{//若优先级和状态均未选中，则直接跳转至最后一个tap
                    	  $('#demo-main-wz').bootstrapWizard('last');
                    	  return false;
                      }

        		}else if(syncFlag == "cts_sync_jira"){
        			 if(document.getElementById("priority").checked){
                    	  $("#cts_priority_mapping").show();
//                          $("#cts_state_mapping").hide();
                          var priorityCheck = true;
             			  var stateCheck = false;
             			  syncData.listPriorityOrState(priorityCheck,stateCheck,projectKey);
                      }else{//若优先级和状态均未选中，则直接跳转至最后一个tap
                    	  $('#demo-main-wz').bootstrapWizard('last');
                    	  return false;
                      }
        		}
        	}

        },
        onTabShow: function(tab, navigation, index) {
            var $total = navigation.find('li').length;
            var $current = index+1;
            var $percent = ($current/$total) * 100;
            var wdt = 100/$total;
            var lft = wdt*index;
            $('#demo-main-wz').find('.progress-bar').css({width:wdt+'%',left:lft+"%", 'position':'relative', 'transition':'all .5s'});
            // If it's the last tab then hide the last button and show the finish instead
            if($current >= $total) {
                $('#demo-main-wz').find('.next').hide();
                $('#demo-main-wz').find('.finish').show();
                $('#demo-main-wz').find('.finish').prop('disabled', false);
            } else {
                $('#demo-main-wz').find('.next').show();
                $('#demo-main-wz').find('.finish').hide().prop('disabled', true);
            }
            if(index == 2){
            	syncData.getTestCycleList();
            	syncData.getComponentList();
            	syncData.getIssueStatus();
            	syncData.getAssignableUser();
            	syncData.getCtsCondition();
            	if(initTableFlag == 0){
            		syncData.init_tab3_table();
            	}else if(initTableFlag == 1){
            		if(syncFlag == "jira_sync_cts"){
            			var params={
    				            silent: true,
    				            url:path+"/jira/queryTestCaseListForPage?jiraProjectId="+jiraProjectId
    		   					+"&&sortColumn="+sortColumn+"&&sort="+sort+"&&status="+status+"&&reporter="+reporter
    		   					+"&&componentForSelect="+componentForSelect+"&&cycleIdAndVersionId="+cycleIdAndVersionId
    				    };
    					$('#jira_sync_cts_table').bootstrapTable('refresh',params);

            		}else if(syncFlag == "cts_sync_jira"){
            			var params={
            		            silent: true,
            		            url:path+"/testCaseController/listTestCaseByCondition?state="+state+"&&iterationId="+iterationId+"&&areaId="+areaId
               					+"&&authorId="+authorId+"&&assignId="+assignId+"&&projectId="+ctsProjectId
            		    };
            			$('#cts_sync_jira_table').bootstrapTable('refresh',params);

            		}

            	}
            }
        }
    });
});
/*=======================================初始化步骤导向结束=====================================*/
var syncData = {
		/*====================================tap1开始=====================================*/
		//获取jira项目列表
		getJiraProject : function(){
			$.ajax({
		    type : "get",
		    async: true,
		    url : path+'/jira/getAllProject',//找到controller里相应的方法
		    success : function(dataMap) {
		    	var jiraProjectList = dataMap.projectList;
		    	$(jiraProjectList).each(function(index,jiraProject){
		    		jiraProjectOntion += '<option value="'+jiraProject.id+'" key="'+jiraProject.key+'">'+jiraProject.name+'</option>';
		    	});
		    	$('#jiraOrCts_project0').html(jiraProjectOntion);

		    	projectKey = $('#jiraOrCts_project0 option:selected').attr('key');
		    	jiraProjectId = $('#jiraOrCts_project0 option:selected').val();
//	        	syncData.listPriorityOrState(projectKey);
		    }
		   });

		},

		//获取cts项目列表
		getCtsProject : function(){
			$.ajax({
		    type : "get",
		    async: true,
		    url : path+'/basic/getProjectByUser',//找到controller里相应的方法
		    success : function(dataList) {
		    	$(dataList).each(function(index,data){
		    		ctsProjectOntion += '<option value="'+data.projectId+'">'+data.projectName+'</option>';
		    	});
		    	$('#jiraOrCts_project1').html(ctsProjectOntion);
		    	ctsProjectId = $('#jiraOrCts_project1 option:selected').val();
		    }
		   });

		},

		//切换同步触发事件
		changeSync : function(){
			if(syncFlag == "jira_sync_cts"){
	    		syncFlag = "cts_sync_jira";
	    		$('#demo-main-tab1 h4').text("cts 同步 jira");

	    		$('#cts_sync_jira_tab1').show();
	    		$('#cts_sync_jira_tab2').show();
	    		$('#cts_sync_jira_tab3').show();

				$('#jira_sync_cts_tab1').hide();
				$('#jira_sync_cts_tab2').hide();
				$('#jira_sync_cts_tab3').hide();

	    		$('#jiraOrCts_project0').html(ctsProjectOntion);

	        	$('#jiraOrCts_project1').html(jiraProjectOntion);


	    	}else if(syncFlag == "cts_sync_jira"){
	    		syncFlag = "jira_sync_cts";
	    		$('#demo-main-tab1 h4').text("jira 同步 cts");

	    		$('#jira_sync_cts_tab1').show();
	    		$('#jira_sync_cts_tab2').show();
	    		$('#jira_sync_cts_tab3').show();

				$('#cts_sync_jira_tab1').hide();
				$('#cts_sync_jira_tab2').hide();
				$('#cts_sync_jira_tab3').hide();

	    		$('#jiraOrCts_project0').html(jiraProjectOntion);

	        	$('#jiraOrCts_project1').html(ctsProjectOntion);

	    	}



		},
		//是否全选触发事件
		checkAll : function(){
			var name;
			var checked;
			if(syncFlag == "jira_sync_cts"){
				name = "jira_param";
				if(document.getElementById("jira_checkedAll").checked){
					checked = true;
				}else{
					document.getElementById("jira-name").checked = true;
					document.getElementById("jira-author").checked = true;
					checked = false;
				}

			}else if(syncFlag == "cts_sync_jira"){
				name = "cts_param";
				if(document.getElementById("cts_checkedAll").checked){
					checked = true;
				}else{
					document.getElementById("name").checked = true;
					document.getElementById("author").checked = true;
					checked = false;
				}

			}

			 //根据名字获取所有checkbox控件
			   var allCheckBoxs=document.getElementsByName(name) ;
			   //循环设置控件为选中状态
			   for (var i=0;i<allCheckBoxs.length ;i++){
			       if(allCheckBoxs[i].type=="checkbox"){
			              allCheckBoxs[i].checked=checked;
			       }
			    }
			   //name、author默认选中
			   if(syncFlag == "jira_sync_cts"){
					if(!document.getElementById("jira_checkedAll").checked){
						document.getElementById("jira-name").checked = true;
						document.getElementById("jira-author").checked = true;
					}

				}else if(syncFlag == "cts_sync_jira"){
					if(!document.getElementById("cts_checkedAll").checked){
						document.getElementById("name").checked = true;
						document.getElementById("author").checked = true;
					}

				}

		},


		/*====================================tap1结束=====================================*/

		/*====================================tap2开始=====================================*/
		 //获取jira和cts优先级或状态列表
		listPriorityOrState : function(priorityCheck,stateCheck,projectKey){
			console.log("priorityCheck: "+priorityCheck);
			console.log("stateCheck: "+stateCheck);
			console.log("projectKey: "+projectKey);
			$.ajax({
			    type : "get",
			    async: true,
			    url : path+'/testCaseController/listPriorityOrState?priorityCheck='+priorityCheck+'&&stateCheck='+stateCheck+'&&projectKey='+projectKey,//找到controller里相应的方法
//			    beforeSend: function(XMLHttpRequest){
//
//	        	},
			    success : function(dataMap) {
			    	console.log("dataMap: "+JSON.stringify(dataMap));
			    	var jiraPriorityList = dataMap.jiraPriority;
			    	var ctsPriorityList = dataMap.ctsPriority;
			    	var jiraStateList = dataMap.jiraState;
			    	var ctsStateList = dataMap.ctsState;
			    	console.log("jiraPriorityList: "+JSON.stringify(jiraPriorityList));
			    	console.log("ctsPriorityList: "+JSON.stringify(ctsPriorityList));
			    	//cts中priority的下拉列表
			    	var ctsPriorityOption = "";
		    		$(ctsPriorityList).each(function(index,ctsPriority){
		    			ctsPriorityOption += '<option value="'+ctsPriority.id+'">'+ctsPriority.name+'</option>';
			    	});

		    		//cts中state的下拉列表
		    		var ctsStateOption = "";
		    		$(ctsStateList).each(function(index,ctsState){
		    			ctsStateOption += '<option value="'+ctsState.id+'">'+ctsState.name+'</option>';
			    	});

		    		//jira中priority的下拉列表
			    	var jiraPriorityOption = "";
		    		$(jiraPriorityList).each(function(index,jiraPriority){
		    			jiraPriorityOption += '<option value="'+jiraPriority.id+'">'+jiraPriority.name+'</option>';
			    	});

		    		//jira中state的下拉列表
			    	var jiraStateOption = "";
		    		$(jiraStateList).each(function(index,jiraState){
		    			jiraStateOption += '<option value="'+jiraState.id+'">'+jiraState.name+'</option>';
			    	});


			    	//jira同步cts的priority字段映射
					var jira_priority_mapping_div = '<div class = "form-group label-height">'
																			+'<label class="col-sm-2 col-sm-offset-2 control-label">jira</label>'
																			+'<label class="col-sm-2 col-sm-offset-4 control-label">cts</label>'
																		+'</div>';


			    	$(jiraPriorityList).each(function(index,jiraPriority){
			    		jira_priority_mapping_div += '<div class ="form-group lable-body">'
					    													+'<label class="col-sm-2 col-sm-offset-2 control-label">'+jiraPriority.name+'</label>'
					    													+'<label class="col-sm-1 col-sm-offset-1 control-label">→</label>'
					    													+'<select class="col-sm-3 col-sm-offset-1 form-control" id="'+jiraPriority.id+'" name="'+jiraPriority.name+'">';
				    		jira_priority_mapping_div += ctsPriorityOption;
				    		jira_priority_mapping_div += '</select>'
			    													+'</div>';
			    	});
			    	$("#jira_priority_mapping .panel-body").html(jira_priority_mapping_div);


			    	//jira同步cts的state字段映射
					var jira_state_mapping_div = '<div class = "form-group label-height">'
																		+'<label class="col-sm-2 col-sm-offset-2 control-label">jira</label>'
																		+'<label class="col-sm-2 col-sm-offset-4 control-label">cts</label>'
																	+'</div>';


			    	$(jiraStateList).each(function(index,jiraState){
			    		jira_state_mapping_div += '<div class ="form-group lable-body">'
					    													+'<label class="col-sm-2 col-sm-offset-2 control-label">'+jiraState.name+'</label>'
					    													+'<label class="col-sm-1 col-sm-offset-1 control-label">→</label>'
					    													+'<select class="col-sm-3 col-sm-offset-1 form-control" id="'+jiraState.id+'" name="'+jiraState.name+'">';
					    		jira_state_mapping_div += ctsStateOption;
					    		jira_state_mapping_div += '</select>'
			    													+'</div>';
			    	});
			    	$("#jira_state_mapping .panel-body").html(jira_state_mapping_div);


			    	//cts同步jira的priority字段映射
					var cts_priority_mapping_div = '<div class = "form-group label-height">'
																			+'<label class="col-sm-2 col-sm-offset-2 control-label">cts</label>'
																			+'<label class="col-sm-2 col-sm-offset-4 control-label">jira</label>'
																		+'</div>';



			    	$(ctsPriorityList).each(function(index,ctsPriority){
			    		cts_priority_mapping_div += '<div class ="form-group lable-body">'
					    													+'<label class="col-sm-2 col-sm-offset-2 control-label">'+ctsPriority.name+'</label>'
					    													+'<label class="col-sm-1 col-sm-offset-1 control-label">→</label>'
					    													+'<select class="col-sm-3 col-sm-offset-1 form-control" id="'+ctsPriority.id+'" name="'+ctsPriority.name+'">';
				    		cts_priority_mapping_div += jiraPriorityOption;
				    		cts_priority_mapping_div += '</select>'
			    													+'</div>';
			    	});
			    	$("#cts_priority_mapping .panel-body").html(cts_priority_mapping_div);

			    	//cts同步jira的state字段映射
//					var cts_state_mapping_div = '<div class = "form-group label-height">'
//																		+'<label class="col-sm-2 col-sm-offset-2 control-label">cts</label>'
//																		+'<label class="col-sm-2 col-sm-offset-4 control-label">jira</label>'
//																	+'</div>';
//
//
//
//			    	$(ctsStateList).each(function(index,ctsState){
//			    		cts_state_mapping_div += '<div class ="form-group lable-body">'
//					    													+'<label class="col-sm-2 col-sm-offset-2 control-label">'+ctsState.name+'</label>'
//					    													+'<label class="col-sm-1 col-sm-offset-1 control-label">→</label>'
//					    													+'<select class="col-sm-3 col-sm-offset-1 form-control" id="'+ctsState.id+'" name="'+ctsState.name+'">';
//					    		cts_state_mapping_div += jiraStateOption;
//					    		cts_state_mapping_div += '</select>'
//			    													+'</div>';
//			    	});
//			    	$("#cts_state_mapping .panel-body").html(cts_state_mapping_div);
			    }
//			    complete: function(XMLHttpRequest, textStatus){
//
//
//	        	}
			   });




		},
//		mappingChange : function(el){
//			var key = $(el).attr("id");
//			var value = $('#'+key+' option:selected').val();
//			console.log("key: "+key);
//			console.log("value: "+value);
//		},
		/*====================================tap2结束=====================================*/

		/*====================================tap3开始=====================================*/
		//初始化jira_sync_cts_table和cts_sync_jira_table
		init_tab3_table : function(){
			initTableFlag = 1;
			 var sortColumn = "";
   		  	 var sort = "";

   		  console.log("jiraProjectId: "+jiraProjectId);
   			$('#jira_sync_cts_table').bootdatagrid(
   					path+"/jira/queryTestCaseListForPage?jiraProjectId="+jiraProjectId
   					+"&&sortColumn="+sortColumn+"&&sort="+sort+"&&status="+status+"&&reporter="+reporter
   					+"&&componentForSelect="+componentForSelect+"&&cycleIdAndVersionId="+cycleIdAndVersionId, {
   						pagination : true,
   						pageNumber : 1,
   						pageSize : 5,
   						dataType:'json',
   						singleSelect : false,
   						striped : true,
   						clickToSelect : true,
   						onLoadSuccess: function(data){
   			               $('#jira-total-num').text(data.total);
   			               if(document.getElementById("jira_table_checkedAll").checked){
   			            	$('#jira_sync_cts_table').bootstrapTable('checkAll');
   			               }
   			            }
   			});



   			$('#cts_sync_jira_table').bootdatagrid(
   					path+"/testCaseController/listTestCaseByCondition?state="+state+"&&iterationId="+iterationId+"&&areaId="+areaId
   					+"&&authorId="+authorId+"&&assignId="+assignId+"&&projectId="+ctsProjectId, {
   						pagination : true,
   						pageNumber : 1,
   						pageSize : 5,
   						dataType:'json',
   						singleSelect : false,
   						striped : true,
   						clickToSelect : true,
   						onLoadSuccess: function(data){
			               $('#total-num').text(data.total);
			               if(document.getElementById("cts_table_checkedAll").checked){
			            	$('#cts_sync_jira_table').bootstrapTable('checkAll');
			               }
			            }
   			});



		},

		/*======================jira_sync_cts_table查询条件初始化=====================*/
		//获取测试循环列表
		getTestCycleList : function(){
			$.ajax({
			    type : "get",
			    async: true,
			    url : path+"/jira/getTestCycleListByCondition?projectId="+jiraProjectId,//找到controller里相应的方法
			    beforeSend: function(XMLHttpRequest){
	        	},
			    success : function(dataList) {
			    	$("#cycleId").html("<option value=''>全部</option>");
    		    	$(dataList).each(function(index,data){
    		    		$("#cycleId").append("<option value='"+data.id+","+data.versionId+"'>"+data.name+"("+data.versionName+")"+"</option>");
    				});
			    },
			    complete: function(XMLHttpRequest, textStatus){
	        	}
			   });
		},
		//获取模块列表
		getComponentList : function(){
			$.ajax({
			    type : "get",
			    async: true,
			    url : path+"/jira/getComponentListByProject?projectKeyOrId="+jiraProjectId,//找到controller里相应的方法
			    beforeSend: function(XMLHttpRequest){
	        	},
			    success : function(dataList) {
			    	$("#componentId").html("<option value=''>全部</option>");
    		    	$(dataList).each(function(index,data){
    		    		$("#componentId").append("<option value="+data.id+">"+data.name+"</option>");
    				});
			    },
			    complete: function(XMLHttpRequest, textStatus){
	        	}
			   });
		},

		//获取结果列表
		getIssueStatus : function(){
			$.ajax({
			    type : "get",
			    async: true,
			    url : path+"/jira/getIssueStatus?projectKey="+projectKey,//找到controller里相应的方法
			    beforeSend: function(XMLHttpRequest){
	        	},
			    success : function(dataList) {
			    	$("#issueStatus").html("<option value=''>全部</option>");
    		    	$(dataList).each(function(index,data){
    		    		$("#issueStatus").append("<option value="+data.id+">"+data.name+"</option>");
    				});
			    },
			    complete: function(XMLHttpRequest, textStatus){
	        	}
			   });
		},
		//获取报告人列表
		getAssignableUser : function(){
			$.ajax({
    	        type : "post",
    	        url : path+'/jira/getAssignableUser',//找到controller里相应的方法
    	        data : {"projectKey":projectKey}, //把数组的值赋给data，把上面的param改为data,这里就能直接去掉
    	        dataType : "json",//根据数据类型选择text、jason等
    	        beforeSend: function(XMLHttpRequest){
	        	},
	        	complete: function(XMLHttpRequest, textStatus){
	        	},
    	        success : function(dataList) {
    	        	$("#reporter").html("<option value=''>全部</option>");
    		    	$(dataList).each(function(index,data){
    		    		$("#reporter").append("<option value="+data.userAccount+">"+data.userName+"</option>");
    				});
    	        }
    	       });


		},

		//测试循环change事件
		cycleIdChange : function(){

			cycleIdAndVersionId = $('#cycleId option:selected').val();
			var params={
		            silent: true,
		            url:path+"/jira/queryTestCaseListForPage?jiraProjectId="+jiraProjectId
   					+"&&sortColumn="+sortColumn+"&&sort="+sort+"&&status="+status+"&&reporter="+reporter
   					+"&&componentForSelect="+componentForSelect+"&&cycleIdAndVersionId="+cycleIdAndVersionId
		    };
			$('#jira_sync_cts_table').bootstrapTable('refresh',params);
		},

		//模块change事件
		componentIdChange : function(){

			componentForSelect = $('#componentId option:selected').text();
			if(componentForSelect == "全部"){

				componentForSelect = "";
			}
			console.log("componentForSelect: "+componentForSelect);
			console.log("cycleIdAndVersionId: "+cycleIdAndVersionId);
			var params={
		            silent: true,
		            url:path+"/jira/queryTestCaseListForPage?jiraProjectId="+jiraProjectId
   					+"&&sortColumn="+sortColumn+"&&sort="+sort+"&&status="+status+"&&reporter="+reporter
   					+"&&componentForSelect="+componentForSelect+"&&cycleIdAndVersionId="+cycleIdAndVersionId
		    };
			$('#jira_sync_cts_table').bootstrapTable('refresh',params);
		},

		//结果change事件
		issueStatusChange : function(){

			status = $('#issueStatus option:selected').val();
			var params={
		            silent: true,
		            url:path+"/jira/queryTestCaseListForPage?jiraProjectId="+jiraProjectId
   					+"&&sortColumn="+sortColumn+"&&sort="+sort+"&&status="+status+"&&reporter="+reporter
   					+"&&componentForSelect="+componentForSelect+"&&cycleIdAndVersionId="+cycleIdAndVersionId
		    };
			$('#jira_sync_cts_table').bootstrapTable('refresh',params);
		},

		//报告人change事件
		reporterChange : function(){

			reporter = $('#reporter option:selected').val();
			var params={
		            silent: true,
		            url:path+"/jira/queryTestCaseListForPage?jiraProjectId="+jiraProjectId
   					+"&&sortColumn="+sortColumn+"&&sort="+sort+"&&status="+status+"&&reporter="+reporter
   					+"&&componentForSelect="+componentForSelect+"&&cycleIdAndVersionId="+cycleIdAndVersionId
		    };
			$('#jira_sync_cts_table').bootstrapTable('refresh',params);
		},
		//jira_sync_cts_table重置事件
		jira_reset : function(){
			$('#cycleId').val("");
			$('#componentId').val("");
			$('#issueStatus').val("");
			$('#reporter').val("");
			sortColumn = "";
			sort = "";
			status = "";
			reporter = "";
			componentForSelect = "";
			cycleIdAndVersionId = "";
			var params={
		            silent: true,
		            url:path+"/jira/queryTestCaseListForPage?jiraProjectId="+jiraProjectId
   					+"&&sortColumn="+sortColumn+"&&sort="+sort+"&&status="+status+"&&reporter="+reporter
   					+"&&componentForSelect="+componentForSelect+"&&cycleIdAndVersionId="+cycleIdAndVersionId
		    };
			$('#jira_sync_cts_table').bootstrapTable('refresh',params);

		},
		/*======================jira_sync_cts_table查询条件初始化结束=====================*/

		/*======================cts_sync_jira_table查询条件初始化=====================*/
		getCtsCondition : function(){
			$.ajax({
			    type : "get",
			    async: true,
			    url : path+'/testCaseController/getCondition?',//找到controller里相应的方法
			    beforeSend: function(XMLHttpRequest){

	        	},
			    success : function(dataMap) {
			    	//加载状态下拉列表
			    	var stateList = dataMap.state;
			    	$("#state").html("<option value=''>全部</option>");
			    	$(stateList).each(function(index,state){
			    		$("#state").append("<option value="+state.state+">"+state.name+"</option>");
					});
			    	//加载迭代下拉列表
			    	var iterationList = dataMap.iteration;
			    	$("#iterationId").html("<option value=''>全部</option>");
			    	$(iterationList).each(function(index,iteration){
			    		$("#iterationId").append("<option value="+iteration.id+">"+iteration.name+"</option>");
					});
			    	//加载区域下拉列表
			    	var areaList = dataMap.area;
			    	$("#areaId").html("<option value=''>全部</option>");
			    	$(areaList).each(function(index,area){
			    		$("#areaId").append("<option value="+area.id+">"+area.name+"</option>");
					});
			    	//加载创建人下拉列表
			    	var authorList = dataMap.author;
			    	$("#authorId").html("<option value=''>全部</option>");
			    	$(authorList).each(function(index,author){
			    		$("#authorId").append("<option value="+author.userId+">"+author.userName+"</option>");
					});
			    	//加载指派人下拉列表
			    	var assignerList = dataMap.assigner;
			    	$("#assignId").html("<option value=''>全部</option>");
			    	$(assignerList).each(function(index,assigner){
			    		$("#assignId").append("<option value="+assigner.userId+">"+assigner.userName+"</option>");
					});

			    },
			    complete: function(XMLHttpRequest, textStatus){


	        	}
			   });


		},
		//状态change事件
		stateChange : function(){
			state = $('#state option:selected').val();
			var params={
		            silent: true,
		            url:path+"/testCaseController/listTestCaseByCondition?state="+state+"&&iterationId="+iterationId+"&&areaId="+areaId
   					+"&&authorId="+authorId+"&&assignId="+assignId+"&&projectId="+ctsProjectId
		    };
			$('#cts_sync_jira_table').bootstrapTable('refresh',params);
		},
		//迭代change事件
		iterationIdChange : function(){

			iterationId = $('#iterationId option:selected').val();
			var params={
		            silent: true,
		            url:path+"/testCaseController/listTestCaseByCondition?state="+state+"&&iterationId="+iterationId+"&&areaId="+areaId
   					+"&&authorId="+authorId+"&&assignId="+assignId+"&&projectId="+ctsProjectId
		    };
			$('#cts_sync_jira_table').bootstrapTable('refresh',params);

		},

		//区域change事件
		areaIdChange : function(){

			areaId = $('#areaId option:selected').val();
			var params={
		            silent: true,
		            url:path+"/testCaseController/listTestCaseByCondition?state="+state+"&&iterationId="+iterationId+"&&areaId="+areaId
   					+"&&authorId="+authorId+"&&assignId="+assignId+"&&projectId="+ctsProjectId
		    };
			$('#cts_sync_jira_table').bootstrapTable('refresh',params);

		},

		//创建人change事件
		authorIdChange : function(){

			authorId = $('#authorId option:selected').val();
			var params={
		            silent: true,
		            url:path+"/testCaseController/listTestCaseByCondition?state="+state+"&&iterationId="+iterationId+"&&areaId="+areaId
   					+"&&authorId="+authorId+"&&assignId="+assignId+"&&projectId="+ctsProjectId
		    };
			$('#cts_sync_jira_table').bootstrapTable('refresh',params);

		},

		//指派人change事件
		assignIdChange : function(){

			assignId = $('#assignId option:selected').val();
			var params={
		            silent: true,
		            url:path+"/testCaseController/listTestCaseByCondition?state="+state+"&&iterationId="+iterationId+"&&areaId="+areaId
   					+"&&authorId="+authorId+"&&assignId="+assignId+"&&projectId="+ctsProjectId
		    };
			$('#cts_sync_jira_table').bootstrapTable('refresh',params);

		},
		//cts_sync_jira_table重置事件
		cts_reset : function(){
			$('#state').val("");
			$('#iterationId').val("");
			$('#areaId').val("");
			$('#authorId').val("");
			$('#assignId').val("");
			state = "";
			iterationId = "";
			areaId = "";
			authorId = "";
			assignId = "";
			var params={
		            silent: true,
		            url:path+"/testCaseController/listTestCaseByCondition?state="+state+"&&iterationId="+iterationId+"&&areaId="+areaId
   					+"&&authorId="+authorId+"&&assignId="+assignId+"&&projectId="+ctsProjectId
		    };
			$('#cts_sync_jira_table').bootstrapTable('refresh',params);

		},
		/*======================cts_sync_jira_table查询条件初始化结束=====================*/
		/*====================================tap3结束=====================================*/
		//同步按钮触发事件
		syncJiraOrCts : function(){

			if(syncFlag == "jira_sync_cts"){
				if(document.getElementById("jira_table_checkedAll").checked){
					 layer.confirm('确定要同步当前所有数据吗？', {icon: 3, title:'<span class="glyphicon glyphicon-th-large"></span>&nbsp;提示'}, function(){
						 jira_flag = 0;
						 jira_issueIds = "";
						 syncData.jiraSyncCts(jira_flag,jira_issueIds);
						 layer.closeAll();
					});

				}else{
					jira_flag = 1;
					var getSelections = $('#jira_sync_cts_table').bootstrapTable('getSelections');
					var issueIds = "";
			    	$(getSelections).each(function(index,selection){
			    		issueIds += issueIds==""?"":",";
			    		issueIds += selection.issueId;
					});
					jira_issueIds = issueIds;
					if(jira_issueIds == ""){
						toast.info ('请至少选择一条信息！','信息提示');
					}else{
						syncData.jiraSyncCts(jira_flag,jira_issueIds);
					}

				}


			}else if(syncFlag == "cts_sync_jira"){
				if(document.getElementById("cts_table_checkedAll").checked){
					 layer.confirm('确定要同步当前所有数据吗？', {icon: 3, title:'<span class="glyphicon glyphicon-th-large"></span>&nbsp;提示'}, function(){
						 cts_flag = 0;
						 cts_testcaseIds = "";
						 syncData.ctsSyncJira(cts_flag,cts_testcaseIds);
						 layer.closeAll();
					});

				}else{
					cts_flag = 1;
					var getSelections = $('#cts_sync_jira_table').bootstrapTable('getSelections');
					var testcaseIds = "";
			    	$(getSelections).each(function(index,selection){
			    		testcaseIds += testcaseIds==""?"":",";
			    		testcaseIds += selection.testcaseId;
					});
			    	cts_testcaseIds = testcaseIds;
					if(cts_testcaseIds == ""){
						toast.info ('请至少选择一条信息！','信息提示');
					}else{
						syncData.ctsSyncJira(cts_flag,cts_testcaseIds);
					}


				}

			}

		},
		//jira同步cts触发事件
		jiraSyncCts : function(jira_flag,jira_issueIds){
			//根据名字获取所有checkbox控件
			   var allCheckBoxs=document.getElementsByName("jira_param") ;
			   //循环设置控件获取选中状态字段
			   var ids = "";
			   for (var i=0;i<allCheckBoxs.length ;i++){
				   var id = $(allCheckBoxs[i]).attr("id");
				   if(document.getElementById(id).checked){
					   var str = id.split("-");
					   ids += ids==""?"":",";
					   ids += str[1];
				   }
			    }
			var jira_priority_lableBodyLen = $('#jira_priority_mapping>.panel-body>.lable-body').length;
			for(var i = 0; i < jira_priority_lableBodyLen; i++){
				var select = $($('#jira_priority_mapping>.panel-body>.lable-body')[i]).find("select")[0];
				var key = $(select).attr("id");
				var value = $(select).val();
				jira_priorityJson[key] = value;
			}
			var jira_state_lableBodyLen = $('#jira_state_mapping>.panel-body>.lable-body').length;
			for(var i = 0; i < jira_state_lableBodyLen; i++){
				var select = $($('#jira_state_mapping>.panel-body>.lable-body')[i]).find("select")[0];
				var key = $(select).attr("id");
				var value = $(select).val();
				jira_stateJson[key] = value;
			}
			console.log("jira_stateJson: "+JSON.stringify(jira_stateJson));
			jira_syncParam = ids;
			var params = {
					"flag":jira_flag,
					"jiraProjectId":jiraProjectId,
					"issueIds":jira_issueIds,
					"ctsProjectId":ctsProjectId,
					"syncParam":jira_syncParam,
					"priorityJson":JSON.stringify(jira_priorityJson),
					"stateJson":JSON.stringify(jira_stateJson),
					"status":status,
					"reporter":reporter,
					"module":componentForSelect,
					"testCircle":cycleIdAndVersionId
			};
			console.log("params: "+JSON.stringify(params));
			$.ajax({
    	        type : "post",
    	        url :path+'/testCaseController/jiraSyncCts',//找到controller里相应的方法
    	        data : params, //把数组的值赋给data，把上面的param改为data,这里就能直接去掉
    	        dataType : "json",//根据数据类型选择text、jason等
    	        beforeSend:function(xmlHttp){
    	    		//请求之前 显示加载提示
    	    		if($(".purchase-loading").length == 0){
    	    			toast.loading();
    	    			$(".loading-cont").append("<span>正在同步,可能时间较长,请耐心等待......</span>");
    	    			$(".loading-cont").css({"background-position-y":"10px","width":"137px","height":"116px"});
    	    			$(".loading-cont>span").css({"position":"absolute","top":"80px","color":"#fff","margin":"0 5px"});
    	    		}
    	    		console.log($(".purchase-loading"));
    	    	},
    	        success : function(data) {
    	        	console.log("data: "+JSON.stringify(data));
    	        	parent.toast.success('同步总数:'+data.total+', 同步成功:'+data.success+', 同步失败:'+data.fail,'同步结果');
    	        	parent.layer.closeAll();
    	        },
    	        complete: function (jqXHR) {
    	        	//请求结束之后调用
    	        	toast.hideloading();
    	        }
    	       });


		},

		//jira同步cts触发事件
		ctsSyncJira : function(cts_flag,cts_testcaseIds){
			//根据名字获取所有checkbox控件
			   var allCheckBoxs=document.getElementsByName("cts_param") ;
			   //循环设置控件获取选中状态字段
			   var ids = "";
			   for (var i=0;i<allCheckBoxs.length ;i++){
				   var id = $(allCheckBoxs[i]).attr("id");
				   if(document.getElementById(id).checked){
					   var str = id.split("-");
					   ids += ids==""?"":",";
					   ids += str[1];
				   }
			    }
			   cts_syncParam = ids;



			var cts_priority_lableBodyLen = $('#cts_priority_mapping>.panel-body>.lable-body').length;
			for(var i = 0; i < cts_priority_lableBodyLen; i++){
				var select = $($('#cts_priority_mapping>.panel-body>.lable-body')[i]).find("select")[0];
				var key = $(select).attr("id");
				var selectedVal = $(select).val();
				var value = "";
				for(var j=0; j<select.options.length; j++){
				    if(select.options[j].value == selectedVal){
				    	value = $(select.options[j]).text();
				    }
				}
				cts_priorityJson[key] = value;
			}

			var params = {
					"flag":cts_flag,
					"ctsProjectId":ctsProjectId,
					"testcaseIds":cts_testcaseIds,
					"jiraProjectKey":projectKey,
					"syncParam":cts_syncParam,
					"priorityJson":JSON.stringify(cts_priorityJson),
					"stateJson":JSON.stringify(cts_stateJson),
					"state":state,
					"iterationId":iterationId,
					"areaId":areaId,
					"authorId":authorId,
					"assignId":assignId
			};
			console.log("params: "+JSON.stringify(params));
			$.ajax({
    	        type : "post",
    	        url :path+'/testCaseController/ctsSyncJira',//找到controller里相应的方法
    	        data : params, //把数组的值赋给data，把上面的param改为data,这里就能直接去掉
    	        dataType : "json",//根据数据类型选择text、jason等
    	        beforeSend:function(xmlHttp){
    	    		//请求之前 显示加载提示
    	    		if($(".purchase-loading").length == 0){
    	    			toast.loading();
    	    			$(".loading-cont").append("<span>正在同步,可能时间较长,请耐心等待......</span>");
    	    			$(".loading-cont").css({"background-position-y":"10px","width":"137px","height":"116px"});
    	    			$(".loading-cont>span").css({"position":"absolute","top":"80px","color":"#fff","margin":"0 5px"});
    	    		}
    	    		console.log($(".purchase-loading"));
    	    	},
    	        success : function(data) {
    	        	console.log("data: "+JSON.stringify(data));
    	        	parent.toast.success('同步总数:'+data.total+', 同步成功:'+data.success+', 同步失败:'+data.fail,'同步结果');
    	        	parent.layer.closeAll();
    	        },
    	        complete: function (jqXHR) {
    	        	//请求结束之后调用
    	        	toast.hideloading();
    	        }
    	       });


		},

		//取消按钮触发事件
		closeLayer : function(){
			parent.layer.closeAll();

		}




};